Skip to content

add task solution - #3915

Open
ViktorStupin wants to merge 2 commits into
mate-academy:masterfrom
ViktorStupin:develop
Open

add task solution#3915
ViktorStupin wants to merge 2 commits into
mate-academy:masterfrom
ViktorStupin:develop

Conversation

@ViktorStupin

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

There are two critical issues that must be addressed before approval:

  1. Incorrect removal from Animal.alive: The code uses indexOf and splice to remove dead animals, but the requirements and checklist explicitly state that you must use Array.prototype.filter for this purpose. This is a technical constraint and a core requirement.

  2. Incorrect removal condition: Animals are only removed from Animal.alive when their health === 0, but the requirement is to remove them when health <= 0. This means animals with negative health could remain in the array, which breaks the contract that Animal.alive only contains alive animals.

To fix these issues:

  • Refactor your removal logic to use filter, for example:
    Animal.alive = Animal.alive.filter(animal => animal.health > 0);
  • Ensure this filtering happens after any change to an animal's health, and that it removes all animals with health <= 0.

Everything else in your implementation looks solid, especially your use of inheritance and method logic. Once you address these blockers, your code should meet all requirements. Keep up the good work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/herbivoresAndCarnivores.js Outdated
Comment on lines +30 to +33
const index = Animal.alive.indexOf(animal);

if (index > -1) {
Animal.alive.splice(index, 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item: 'The Animal.alive array must be updated using Array.prototype.filter to remove dead animals (with health <= 0). Avoid using nested loops or indexOf + splice for this purpose.'

You are using indexOf and splice instead of filter to remove dead animals from Animal.alive.

Comment thread src/herbivoresAndCarnivores.js Outdated
if (animal instanceof Herbivore && !animal.hidden) {
animal.health -= 50;

if (animal.health === 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the requirement that animals must be removed from Animal.alive when their health is less than or equal to 0. Your code only removes them when health === 0. It should be health <= 0.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

All core requirements for the Animal, Herbivore, and Carnivore classes are fully met. The code correctly implements ES6 class inheritance, property management, and the required methods (hide and bite) with proper logic. The Animal.alive array is always up to date, and all technical and stylistic constraints are satisfied. There are no critical issues or blockers. Great job on a clean and robust implementation!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants